package org.idea.spring.bean.jdk;

import java.beans.beancontext.BeanContext;
import java.beans.beancontext.BeanContextServices;
import java.beans.beancontext.BeanContextServicesSupport;
import java.beans.beancontext.BeanContextSupport;
import java.util.Iterator;

/**
 * @Author linhao
 * @Date created in 8:30 下午 2021/4/10
 */
public class BeanContextDemo {

    private static class User{
        int id;

        public User(int id) {
            this.id = id;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    '}';
        }
    }

    public static void main(String[] args) {
        BeanContextServices beanContextServices = new BeanContextServicesSupport();
        for (int i=0;i<10;i++){
            User user = new User(1);
            beanContextServices.add(user);
        }
        Iterator<User> iterator = beanContextServices.getCurrentServiceSelectors(User.class);
        while(iterator!=null && iterator.hasNext()) {
            User user = iterator.next();
            System.out.println(user.toString());
        }
        System.out.println("end");
    }
}
